﻿using System;

using DevExpress.Xpo;

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using System.ComponentModel;
using DevExpress.ExpressApp;
using DevExpress.Data.Filtering;

namespace SpeedSCM.Module
{
    [NavigationItem("库存管理")]
    [ImageName("BO_Sale_Item_v92")]
    public class 商品调价单 : 单据
    {
        public 商品调价单(Session session)
            : base(session)
        {

        }
        protected override SeedType SeedType
        {
            get { return SeedType.商品调价单; }
        }

        private 仓库 _调价仓库;
        [Custom("Caption", "调价仓库")]
        [RuleRequiredField(null, DefaultContexts.Save, "必须选择调价仓库")]
        public 仓库 调价仓库
        {
            get { return _调价仓库; }
            set { SetPropertyValue<仓库>("调价仓库", ref _调价仓库, value); }
        }

        [Association("商品调价单-商品调价单明细")]
        public XPCollection<商品调价单明细> 商品调价单明细
        {
            get { return GetCollection<商品调价单明细>("商品调价单明细"); }
        }
        public override bool Excute(IObjectSpace objectSpace)
        {
            return base.Excute(objectSpace);
        }
    }

    [ImageName("BO_Sale_Item_v92")]
    [RuleCombinationOfPropertiesIsUnique(null, DefaultContexts.Save, "商品调价单,商品名称", CustomMessageTemplate = "商品调价单中已经存在该商品")]
    public class 商品调价单明细 : BaseObject
    {
        public 商品调价单明细(Session session)
            : base(session)
        {

        }
        private 商品调价单 _商品调价单;
        [Custom("Caption", "商品调价单")]
        [Association("商品调价单-商品调价单明细")]
        [Custom("AllowEdit", "False")]
        public 商品调价单 商品调价单
        {
            get { return _商品调价单; }
            set { SetPropertyValue<商品调价单>("商品调价单", ref _商品调价单, value); }
        }
        private 商品 _商品名称;
        [Custom("Caption", "商品名称")]
        [RuleRequiredField(null, DefaultContexts.Save, "必须选择商品")]
        public 商品 商品名称
        {
            get { return _商品名称; }
            set
            {
                if (SetPropertyValue<商品>("商品名称", ref _商品名称, value))
                {
                    单价 = value.进货价;
                }
            }
        }
        private decimal _数量;
        [Custom("Caption", "数量")]
        [Custom("EditMask", "n2")]
        [Custom("DisplayFormat", "{0:n2}")]
        [RuleRequiredField]
        public decimal 数量
        {
            get { return _数量; }
            set { SetPropertyValue<decimal>("数量", ref _数量, value); }
        }
        private decimal _单价;
        [Custom("Caption", "单价")]
        [RuleRequiredField]
        public decimal 单价
        {
            get { return _单价; }
            set { SetPropertyValue<decimal>("单价", ref _单价, value); }
        }
        public decimal 金额
        {
            get { return 数量 * 单价; }
        }
        private string _备注;
        [Custom("Caption", "备注")]
        [Size(500)]
        public string 备注
        {
            get { return _备注; }
            set { SetPropertyValue<string>("备注", ref _备注, value); }
        }
    }
}
